RealDID
DID_Haw <- read.csv("~/Desktop/POL 345/JP Folder/DID Calculations_excel.csv")
DID_Wash <-read.csv("~/Desktop/POL 345/JP Folder/DID_Wash.csv")
HawDifB <- (DID_Haw$Asian_Pop.[5]-DID_Haw$Asian_Pop.[1])/4
HawDifB
#0.00763921
HawDifA <- (DID_Haw$Asian_Pop.[11]-DID_Haw$Asian_Pop.[7])/4
HawDifA
#-0.005251658
HawDif<- HawDifA-HawDifB
HawDif
WashDif<- WashDifA-WashDifB
WashDif
#0.01033577
RealDID <- HawDif-WashDif
RealDID
t.test(DIDcomparisons$HA-DIDcomparisons$HB, DIDcomparisons$WA-DIDcomparisons$WB)
grace <- read.csv("~/Desktop/POL 345/JP Folder/GracesTest.csv")
t.test(grace$X-grace$X.1, grace$X.2-grace$X.3)
View(grace)
knitr::opts_chunk$set(echo = TRUE)
#DATA FOR 1990
#loading the data and subsetting for Hawaii in 1990
Data1990 <- read.csv("~/Desktop/POL 355/JP Folder/Data1990.csv")
yearsHawaii <- c(1993, 1997, 1998, 1999, 2003)
yearsWash<- c(1993, 1997, 1998, 1999, 2003)
HwhiteUnemp <- c(0.0387931, 0.06030151, 0.05882353,0.0733945, 0.0733945, 0.08854167, 0.0591716, 0.03482587, 0.04, 0.05586592, 0.05434783)
HblackUnemp <- c(0.1428571, 0.25, NA,0.1666667, 0.125, 0.1666667, 0.09090909, NA, 0.09090909, 0.1875, 0.03846154)
HasianUnemp <- c(0.03303965, 0.05156951, 0.04651163, 0.05720339, 0.06359649, 0.04232804, 0.0547619, 0.05567929, 0.03261803, 0.04024497, 0.03375527)
#making the plot for Hawaii
plot(yearsHawaii, HwhiteUnemp, main = "Unemp Rate for Hawaiian State Pop '93-'03", ylim=c(0, 0.17), type="o", ylab="Unemployment Rate", xlab = "Year")
yearsHawaii <- c(1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003)
yearsWash<- c(1993, 1997, 1998, 1999, 2003)
HwhiteUnemp <- c(0.0387931, 0.06030151, 0.05882353,0.0733945, 0.0733945, 0.08854167, 0.0591716, 0.03482587, 0.04, 0.05586592, 0.05434783)
HblackUnemp <- c(0.1428571, 0.25, NA,0.1666667, 0.125, 0.1666667, 0.09090909, NA, 0.09090909, 0.1875, 0.03846154)
HasianUnemp <- c(0.03303965, 0.05156951, 0.04651163, 0.05720339, 0.06359649, 0.04232804, 0.0547619, 0.05567929, 0.03261803, 0.04024497, 0.03375527)
#making the plot for Hawaii
plot(yearsHawaii, HwhiteUnemp, main = "Unemp Rate for Hawaiian State Pop '93-'03", ylim=c(0, 0.17), type="o", ylab="Unemployment Rate", xlab = "Year")
lines(yearsHawaii, HblackUnemp, col="blue")
lines(yearsHawaii, HasianUnemp, col="red")
abline(v=1998, col="brown")
#making the plot for Hawaii
plot(yearsHawaii, HwhiteUnemp, main = "Unemp Rate of Cahange for Haw.Pop '93-'03", ylim=c(0, 0.30), type="o", ylab="Unemployment Rate", xlab = "Year")
lines(yearsHawaii, HblackUnemp, col="blue")
lines(yearsHawaii, HasianUnemp, col="red")
abline(v=1998, col="brown")
HblackUnemp <- c(0.1428571, 0.25, 0.25 ,0.1666667, 0.125, 0.1666667, 0.09090909, 0.09, 0.09090909, 0.1875, 0.03846154)
plot(yearsHawaii, HwhiteUnemp, main = "Unemp Rate of Cahange for Haw.Pop '93-'03", ylim=c(0, 0.30), type="o", ylab="Unemployment Rate", xlab = "Year")
lines(yearsHawaii, HblackUnemp, col="blue")
lines(yearsHawaii, HasianUnemp, col="red")
abline(v=1998, col="brown")
HblackUnemp <- c(0.1428571, 0.25, 0.25 ,0.1666667, 0.125, 0.1666667, 0.09090909, 0.05, 0.09090909, 0.1875, 0.03846154)
#making the plot for Hawaii
plot(yearsHawaii, HwhiteUnemp, main = "Unemp Rate of Cahange for Haw.Pop '93-'03", ylim=c(0, 0.30), type="o", ylab="Unemployment Rate", xlab = "Year")
lines(yearsHawaii, HblackUnemp, col="blue")
lines(yearsHawaii, HasianUnemp, col="red")
abline(v=1998, col="brown")
plot(yearsHawaii, HwhiteUnemp, main = "Unemp Rate for Haw.Pop '93-'03", ylim=c(0, 0.30), type="o", ylab="Unemployment Rate", xlab = "Year")
lines(yearsHawaii, HblackUnemp, col="blue")
lines(yearsHawaii, HasianUnemp, col="red")
abline(v=1998, col="brown")
WwhiteUnemp
WwhiteUnemp <- c(0.08609272, 0.07912688, 0.06544503, 0.07397959, 0.05440415, 0.04779412, 0.04750594, 0.05141388, 0.06195787, 0.06892231, 0.07851491)
View(DID_Wash)
#Now for washington state
yearsWash<- c(1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003)
WwhiteUnemp <- c(0.08609272, 0.07912688, 0.06544503, 0.07397959, 0.05440415, 0.04779412, 0.04750594, 0.05141388, 0.06195787, 0.06892231, 0.07851491)
WblackUnemp <- c(0.1428571, 0.1428571, NA, 0.15, 0.06666667, 0.1764706, NA, 0.04347826, 0.1111111, 0.1408451, 0.21875)
WasianUnemp <- c(0.07142857, NA, 0.04166667, 0.08108108, 0.06, 0.02083333, 0.02564103, NA, 0.01652893, 0.03225806, 0.05555556)
plot(yearsHawaii, HwhiteUnemp, main = "Unemp Rate for Haw.Pop '93-'03", ylim=c(0, 0.30), type="o", ylab="Unemployment Rate", xlab = "Year")
lines(yearsHawaii, HblackUnemp, col="blue")
lines(yearsHawaii, HasianUnemp, col="red")
abline(v=1998, col="brown")
plot(yearsHawaii, HasianUnemp, main = "Unemp Rate for Haw.Pop '93-'03", ylim=c(0, 0.30), type="o", ylab="Unemployment Rate", xlab = "Year")
lines(yearsHawaii, HblackUnemp, col="blue")
lines(yearsHawaii, HwhiteUnemp, col="red")
abline(v=1998, col="brown")
plot(yearsWash, WasianUnemp, main = "Unemp Rate for Wash. Pop. '93-'03", ylim=c(0, 0.30), type="o", ylab="Unemployment Rate", xlab = "Year")
lines(yearsHawaii, WblackUnemp, col="blue")
lines(yearsHawaii, WwhiteUnemp, col="red")
abline(v=1998, col="brown")
yearsWash<- c(1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003)
WwhiteUnemp <- c(0.08609272, 0.07912688, 0.06544503, 0.07397959, 0.05440415, 0.04779412, 0.04750594, 0.05141388, 0.06195787, 0.06892231, 0.07851491)
WblackUnemp <- c(0.1428571, 0.1428571, 0.14642855, 0.15, 0.06666667, 0.1764706, 0.10997443, 0.04347826, 0.1111111, 0.1408451, 0.21875)
WasianUnemp <- c(0.07142857, 0.05654762, 0.04166667, 0.08108108, 0.06, 0.02083333, 0.02564103, 0.02108498, 0.01652893, 0.03225806, 0.05555556)
#making Washington's plot
plot(yearsWash, WasianUnemp, main = "Unemp Rate for Wash. Pop. '93-'03", ylim=c(0, 0.30), type="o", ylab="Unemployment Rate", xlab = "Year")
lines(yearsHawaii, WblackUnemp, col="blue")
lines(yearsHawaii, WwhiteUnemp, col="red")
abline(v=1998, col="brown")
#lol
#PLOT FOR WHITE UNEMPLOYMENT RATE HAWAII
#setting a years var
yearsHawaii <- c(1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003)
yearsWash<- c(1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003)
HwhiteUnemp <- c(0.0387931, 0.06030151, 0.05882353,0.0733945, 0.0733945, 0.08854167, 0.0591716, 0.03482587, 0.04, 0.05586592, 0.05434783)
HblackUnemp <- c(0.1428571, 0.25, 0.20833335 ,0.1666667, 0.125, 0.1666667, 0.09090909, 0.09090909, 0.09090909, 0.1875, 0.03846154)
HasianUnemp <- c(0.03303965, 0.05156951, 0.04651163, 0.05720339, 0.06359649, 0.04232804, 0.0547619, 0.05567929, 0.03261803, 0.04024497, 0.03375527)
#making the plot for Hawaii
plot(yearsHawaii, HasianUnemp, main = "Unemp Rate for Haw.Pop '93-'03", ylim=c(0, 0.30), type="o", ylab="Unemployment Rate", xlab = "Year")
lines(yearsHawaii, HblackUnemp, col="blue")
lines(yearsHawaii, HwhiteUnemp, col="red")
abline(v=1998, col="brown")
#adding a legend
legend ("topright", c("Black Pop","White Pop", "Asian/Pac Isl Pop"),
lty=c(1,1),
lwd=c(2,2),col=c("blue","black", "red"))
#Now for washington state
yearsWash<- c(1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003)
WwhiteUnemp <- c(0.08609272, 0.07912688, 0.06544503, 0.07397959, 0.05440415, 0.04779412, 0.04750594, 0.05141388, 0.06195787, 0.06892231, 0.07851491)
WblackUnemp <- c(0.1428571, 0.1428571, 0.14642855, 0.15, 0.06666667, 0.1764706, 0.10997443, 0.04347826, 0.1111111, 0.1408451, 0.21875)
WasianUnemp <- c(0.07142857, 0.05654762, 0.04166667, 0.08108108, 0.06, 0.02083333, 0.02564103, 0.02108498, 0.01652893, 0.03225806, 0.05555556)
#making Washington's plot
plot(yearsWash, WasianUnemp, main = "Unemp Rate for Wash. Pop. '93-'03", ylim=c(0, 0.30), type="o", ylab="Unemployment Rate", xlab = "Year")
lines(yearsHawaii, WblackUnemp, col="blue")
lines(yearsHawaii, WwhiteUnemp, col="red")
abline(v=1998, col="brown")
plot(yearsHawaii, HasianUnemp, main = "Unemp Rate for Haw.Pop '93-'03", ylim=c(0, 0.30), type="o", ylab="Unemployment Rate", xlab = "Year")
lines(yearsHawaii, HblackUnemp, col="blue")
lines(yearsHawaii, HwhiteUnemp, col="red")
abline(v=1998, col="brown")
#adding a legend
#legend ("topright", c("Black Pop","White Pop", "Asian/Pac Isl Pop"),
#lty=c(1,1),
#lwd=c(2,2),col=c("blue","black", "red"))
#Now for washington state
yearsWash<- c(1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003)
WwhiteUnemp <- c(0.08609272, 0.07912688, 0.06544503, 0.07397959, 0.05440415, 0.04779412, 0.04750594, 0.05141388, 0.06195787, 0.06892231, 0.07851491)
WblackUnemp <- c(0.1428571, 0.1428571, 0.14642855, 0.15, 0.06666667, 0.1764706, 0.10997443, 0.04347826, 0.1111111, 0.1408451, 0.21875)
WasianUnemp <- c(0.07142857, 0.05654762, 0.04166667, 0.08108108, 0.06, 0.02083333, 0.02564103, 0.02108498, 0.01652893, 0.03225806, 0.05555556)
#making Washington's plot
plot(yearsWash, WasianUnemp, main = "Unemp Rate for Wash. Pop. '93-'03", ylim=c(0, 0.30), type="o", ylab="Unemployment Rate", xlab = "Year")
lines(yearsHawaii, WblackUnemp, col="blue")
lines(yearsHawaii, WwhiteUnemp, col="red")
abline(v=1998, col="brown")
AHawDifB <- (DID_Haw$Asian_Pop.[5]-DID_Haw$Asian_Pop.[1])/4
AHawDifB
#0.00763921
AHawDifA <- (DID_Haw$Asian_Pop.[11]-DID_Haw$Asian_Pop.[7])/4
AHawDifA
#-0.005251658
AHawDif<- AHawDifA-AHawDifB
AHawDif
AWashDifB <- (DID_Wash$Asian_Pop.[5]-DID_Wash$Asian_Pop.[1])/4
AWashDifB
#-0.002857142
AWashDifA <- (DID_Wash$Asian_Pop.[11]-DID_Wash$Asian_Pop.[7])/4
AWashDifA  #0.007478632
AWashDif<- AWashDifA-AWashDifB
AWashDif
#0.01033577
ARealDID <- AHawDif-AWashDif
ARealDID
View(DID_Haw)
BHawDifB <- (DID_Haw$Black_Pop.[5]-DID_Haw$Black_Pop.[1])/4
BHawDifB
BHawDifA <- (DID_Haw$Black_Pop.[11]-DID_Haw$Black_Pop.[7])/4
BHawDifA
BHawDif<- BHawDifA-BHawDifB
BHawDif
BWashDifB <- (DID_Wash$Black_Pop.[5]-DID_Wash$Black_Pop.[1])/4
BWashDifB
BWashDifA <- (DID_Wash$Black_Pop.[11]-DID_Wash$Black_Pop.[7])/4
BWashDifA
BWashDifB
BWashDifA <- (DID_Wash$Black_Pop.[11]-DID_Wash$Black_Pop.[7])/4
BWashDifA
View(DID_Wash)
View(DID_Wash)
BWashDifA <- (DID_Wash$Black_Pop.[11]-0.5)/4
BWashDifA
BWashDif<- BWashDifA-BWashDifB
BWashDif
BRealDID <- BHawDif-BWashDif
BRealDID
BWashDif<- BWashDifA-BWashDifB
BWashDif
BWashDifA <- (DID_Wash$Black_Pop.[11]-0.5)/4
BWashDifA
BWashDifA <- (DID_Wash$Black_Pop.[11]-0.05)/4
BWashDifA
BWashDif<- BWashDifA-BWashDifB
BWashDif
BRealDID <- BHawDif-BWashDif
BRealDID
WHawDifB <- (DID_Haw$White_Pop.[5]-DID_Haw$White_Pop.[1])/4
WHawDifB
WHawDifA <- (DID_Haw$White_Pop.[11]-DID_Haw$White_Pop.[7])/4
WHawDifA
WHawDif<- WHawDifA-WHawDifB
WHawDif
WWashDifB <- (DID_Wash$White_Pop.[5]-DID_Wash$White_Pop.[1])/4
WWashDifB
WWashDifB <- (DID_Wash$White_Pop.[5]-DID_Wash$White_Pop.[1])/4
WWashDifB
WWashDifA <- (DID_Wash$White_Pop.[11]-DID_Wash$White_Pop.[7])/4
WWashDifA
WWashDif<- WWashDifA-WWashDifB
WWashDif
WRealDID <- WHawDif-WWashDif
WRealDID
#loading the data and subsetting for Hawaii in 2000
Data2000 <- read.csv("~/Desktop/POL 345/JP Folder/Data2000.csv")
Haw2000 <- subset(Data2000,Data2000$STATEFIP==15)
#figuring out how many variables we are working with
unique(Haw2000$RACE)
unique(Haw2000$EMPSTAT)
#subsetting by race
Rwhite00 <- subset(Haw2000, Haw2000$RACE==100)
Rblack00<- subset(Haw2000, Haw2000$RACE==200)
RasianMADE00 <- subset(Haw2000, Haw2000$RACE==650| Haw2000$RACE==809| Haw2000$RACE==808| Haw2000$RACE==651| Haw2000$RACE==652)
RNat00 <- subset(Haw2000, Haw2000$RACE==652)
unemp2000Nat <- sum(RNat00$EMPSTAT==21 | RNat00$EMPSTAT==22)/(sum(RNat00$EMPSTAT== 10 | RNat$EMPSTAT==12)+ sum(RNat00$EMPSTAT==21 | RNat00$EMPSTAT==22))
unemp2000Nat
View(DID)
View(grace)
survey <- read.dta13("harris_s1813_spss.dta")
library(readstata13)
library(dplyr)
survey <- read.dta13("harris_s1813_spss.dta")
setwd("~/Dropbox/Perception_Inequality_wHannah/Survey Files/Harris 1968 National Malaise Survey, study no. 1813")
survey <- read.dta13("harris_s1813_spss.dta")
dim(survey)
names(survey)
summary(survey$F7B)
survey$hh <- recode(survey$F7B, 'Male head of household' = "Yes",
'Female head of household (no male head)' = "Yes",
'Wife' = "No", 'Son' = "No",
'Daughter' = "No", 'Other male' = "No",
'Other female' = "No")
summary(survey$hh)
summary(survey$Q6_1)
class(survey$Q6_1)
is.ordered(survey$Q6_1)
survey$inequality <- survey$Q6_1
survey$inequality.variable <- 1
summary(survey$F3_1) #self
summary(survey$F3_2) #other family member
summary(survey$F3_3) #no member in family
survey$union.self <- survey$F3_1
survey$union.other <- survey$F3_2
survey$employed <- survey$Q11A
class(survey$employed)
summary(survey$Q11B)
survey$occupation <-survey$Q11B
class(survey$occupation)
survey$hhsize <- NA
class(survey$hhsize)
summary(survey$F11B)
survey$educ <- survey$F11B
survey$educ <- recode(survey$educ, `8th grade or less` = "Less than high school",
`Some high school` = "Less than high school",
`2-yr cllg grdt (cmmnty cllg, tc )` = "Some college",
`4-year college graduate` = "College graduate")
levels (survey$educ)
summary(survey$educ)
survey$educ <- ordered(survey$educ,
levels = c("Less than high school", "High school graduate",
"Some college", "College graduate", "Post graduate"))
summary(survey$F14)
survey$income <- survey$F14
summary(survey$income)
class(survey$income)
summary(survey$F13_1)
summary(survey$F13_2)
sum(!is.na(survey$F13_1) & !is.na(survey$F13_2))
survey$age <- ifelse(is.na(survey$F13_1), as.character(survey$F13_2), as.character(survey$F13_1))
survey$age <- factor(survey$age)
class(survey$age)
summary(survey$age)
summary(survey$F16)
survey$race <- survey$F16
class(survey$race)
survey$party <- NA
## ideology
survey$ideology <- NA
#gender
summary(survey$F13_1)
summary(survey$F13_2)
survey$gender <- NA
for(i in 1:nrow(survey)){
if(!is.na(survey$F13_1[i])){
survey$gender[i] <- "Male" }
else if(!is.na(survey$F13_2[i])){
survey$gender[i] <- "Female"
}
}
summary(survey$gender)
table(survey$gender)
survey$gender <- as.factor(survey$gender)
summary(survey$gender)
summary(survey$F12)
survey$religion <- survey$F12
class(survey$religion)
survey$religion
survey$hh
survey_1813 <- survey[,c("pid", "study", "year", "urban", "region", "hh", "inequality",
"inequality.variable", "union.self", "union.other",
"employed", "occupation", "hhsize", "educ", "income",
"age", "race", "party", "ideology", "gender", "religion")]
survey <- read.dta13("harris_s1813_spss.dta")
dim(survey)
names(survey)
## pid
survey$pid <- c(1:nrow(survey))
## study value
survey$study <- 1813
## year- value
survey$year <- 1968
## urban- creating NA's
survey$urban <- NA
## region- NA
survey$region <- NA
#respondent name- hh
summary(survey$F7B)
survey$hh <- recode(survey$F7B, 'Male head of household' = "Yes",
'Female head of household (no male head)' = "Yes",
'Wife' = "No", 'Son' = "No",
'Daughter' = "No", 'Other male' = "No",
'Other female' = "No")
summary(survey$hh)
#inequality Q6_1
summary(survey$Q6_1)
class(survey$Q6_1)
is.ordered(survey$Q6_1)
survey$inequality <- survey$Q6_1
survey$inequality.variable <- 1
#union- f3_1; f3_2; f3_3
summary(survey$F3_1) #self
summary(survey$F3_2) #other family member
summary(survey$F3_3) #no member in family
survey$union.self <- survey$F3_1
survey$union.other <- survey$F3_2
#employed -- Q11a
survey$employed <- survey$Q11A
class(survey$employed)
#occupation
summary(survey$Q11B)
survey$occupation <-survey$Q11B
class(survey$occupation)
##hh size
survey$hhsize <- NA
class(survey$hhsize)
#education
summary(survey$F11B)
survey$educ <- survey$F11B
survey$educ <- recode(survey$educ, `8th grade or less` = "Less than high school",
`Some high school` = "Less than high school",
`2-yr cllg grdt (cmmnty cllg, tc )` = "Some college",
`4-year college graduate` = "College graduate")
levels (survey$educ)
summary(survey$educ)
survey$educ <- ordered(survey$educ,
levels = c("Less than high school", "High school graduate",
"Some college", "College graduate", "Post graduate"))
class(survey$educ)
is.ordered(survey$educ)
## income
summary(survey$F14)
survey$income <- survey$F14
summary(survey$income)
class(survey$income)
##age
summary(survey$F13_1)
summary(survey$F13_2)
sum(!is.na(survey$F13_1) & !is.na(survey$F13_2))
survey$age <- ifelse(is.na(survey$F13_1), as.character(survey$F13_2), as.character(survey$F13_1))
survey$age <- factor(survey$age)
class(survey$age)
summary(survey$age)
## race
summary(survey$F16)
survey$race <- survey$F16
class(survey$race)
## politics
survey$party <- NA
## ideology
survey$ideology <- NA
#gender
summary(survey$F13_1)
summary(survey$F13_2)
survey$gender <- NA
for(i in 1:nrow(survey)){
if(!is.na(survey$F13_1[i])){
survey$gender[i] <- "Male" }
else if(!is.na(survey$F13_2[i])){
survey$gender[i] <- "Female"
}
}
summary(survey$gender)
table(survey$gender)
survey$gender <- as.factor(survey$gender)
summary(survey$gender)
##religion
summary(survey$F12)
survey$religion <- survey$F12
class(survey$religion)
### put together data set
survey$religion
survey$hh
survey_1813 <- survey[,c("pid", "study", "year", "urban", "region", "hh", "inequality",
"inequality.variable", "union.self", "union.other",
"employed", "occupation", "hhsize", "educ", "income",
"age", "race", "party", "ideology", "gender", "religion")]
setwd("~/Dropbox/Perception_Inequality_wHannah/Survey Files/Harris 1968 National Malaise Survey, study no. 1813")
library(readstata13)
library(dplyr)
survey <- read.dta13("harris_s1813_spss.dta")
dim(survey)
names(survey)
## pid
survey$pid <- c(1:nrow(survey))
## study value
survey$study <- as.character(1813)
## year- value
survey$year <- 1968
## urban- creating NA's
survey$urban <- NA
## region- NA
survey$region <- NA
#respondent name- hh
summary(survey$F7B)
survey$hh <- recode(survey$F7B, 'Male head of household' = "Yes",
'Female head of household (no male head)' = "Yes",
'Wife' = "No", 'Son' = "No",
'Daughter' = "No", 'Other male' = "No",
'Other female' = "No")
summary(survey$hh)
#inequality Q6_1
summary(survey$Q6_1)
class(survey$Q6_1)
is.ordered(survey$Q6_1)
survey$inequality <- survey$Q6_1
survey$inequality.variable <- 1
#union- f3_1; f3_2; f3_3
summary(survey$F3_1) #self
summary(survey$F3_2) #other family member
summary(survey$F3_3) #no member in family
survey$union.self <- survey$F3_1
survey$union.other <- survey$F3_2
#employed -- Q11a
survey$employed <- survey$Q11A
class(survey$employed)
#occupation
summary(survey$Q11B)
survey$occupation <-survey$Q11B
class(survey$occupation)
##hh size
survey$hhsize <- NA
class(survey$hhsize)
#education
summary(survey$F11B)
survey$educ <- survey$F11B
survey$educ <- recode(survey$educ, `8th grade or less` = "Less than high school",
`Some high school` = "Less than high school",
`2-yr cllg grdt (cmmnty cllg, tc )` = "Some college",
`4-year college graduate` = "College graduate")
levels (survey$educ)
summary(survey$educ)
survey$educ <- ordered(survey$educ,
levels = c("Less than high school", "High school graduate",
"Some college", "College graduate", "Post graduate"))
class(survey$educ)
is.ordered(survey$educ)
## income
summary(survey$F14)
survey$income <- survey$F14
summary(survey$income)
class(survey$income)
##age
summary(survey$F13_1)
summary(survey$F13_2)
sum(is.na(survey$F13_1) & is.na(survey$F13_2))
survey$age <- ifelse(is.na(survey$F13_1), as.character(survey$F13_2), as.character(survey$F13_1))
survey$age <- factor(survey$age)
class(survey$age)
summary(survey$age)
## race
summary(survey$F16)
survey$race <- survey$F16
class(survey$race)
## politics
survey$party <- NA
## ideology
survey$ideology <- NA
#gender
summary(survey$F13_1)
summary(survey$F13_2)
sum(!is.na(survey$F13_2) & !is.na(survey$F13_1))
survey$gender <- NA
for(i in 1:nrow(survey)){
if(!is.na(survey$F13_1[i])){
survey$gender[i] <- "Male" }
else if(!is.na(survey$F13_2[i])){
survey$gender[i] <- "Female"
}
}
summary(survey$gender)
table(survey$gender)
survey$gender <- factor(survey$gender)
##religion
summary(survey$F12)
survey$religion <- survey$F12
class(survey$religion)
### put together data set
survey_1813 <- survey[,c("pid", "study", "year", "urban", "region", "hh", "inequality",
"inequality.variable", "union.self", "union.other",
"employed", "occupation", "hhsize", "educ", "income",
"age", "race", "party", "ideology", "gender", "religion")]
summary(survey_1813)
## save dataset in folder (i.e. working directory must be set to folder)
saveRDS(survey_1813, file = "survey_1813.rds")
